﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using RBS.Common;
using RBS.Web.Controllers;
using Webdiyer.WebControls.Mvc;

namespace RBS.Web.Areas.Deed.Controllers
{
    public class CouponsController : BaseController
    {
        //
        // GET: /Deed/Coupons/ 
        public ActionResult Index()
        {
            return View();
        }
        //list
        public ActionResult SendFoodPaymentList(int id = 1, string kword = null)
        {
            return View(PaymentList(1, id, kword));
        }
        public ActionResult ConsumptionPaymentList(int id = 1, string kword = null)
        {
            return View(PaymentList(2, id, kword));
        }
        public ActionResult AdvertitPaymentList(int id = 1, string kword = null)
        {
            return View(PaymentList(3, id, kword));
        }
        public PagedList<RBS.Core.Model.P_Advertis_Payment> PaymentList(int type = 0, int id = 1, string kword = null)
        {
            const int pageSize = 10;

            var bll = new RBS.Core.BLL.P_Advertis_Payment();
            // var admin = GetAdminInfo(); //取得当前管理员信息
            if (kword != null) kword = kword.Replace("'", "");
            var strTemp = new StringBuilder();
            if (!string.IsNullOrEmpty(kword))
            {
                //strTemp.Append(" and (H_UID like  '%" + kword + "%' or H_UserName like '%" + kword + "%')");
            }
            string strWhere = " and DeedType=  " + type + " and U_Id=" + CurrentUser.Id + strTemp.ToString();
            const string orderby = " id  desc";
            var startIndex = id;

            int totalItems = 0; //要分页的总记录数
            DataTable dt = bll.GetListByUser(pageSize, startIndex, strWhere, orderby, out totalItems).Tables[0];
            //PagedList构造函数 
            var list = IListDataSet.DataTableToIList<RBS.Core.Model.P_Advertis_Payment>(dt);
            PagedList<RBS.Core.Model.P_Advertis_Payment> arts = null;
            if (list != null)
                arts = new PagedList<RBS.Core.Model.P_Advertis_Payment>(list, id, pageSize, totalItems);
            else
            {
                list = new List<RBS.Core.Model.P_Advertis_Payment>();
                arts = new PagedList<RBS.Core.Model.P_Advertis_Payment>(list, id, pageSize, totalItems);
            }
            return arts;
        }

        public ActionResult GiftUser(string abid)
        {
            return View();
        }
    }
}
